package com.example.bms.user.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.bms.user.entity.UserinfoEntity;
import com.example.bms.user.service.UserinfoService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * 
 *
 * @author Jiang
 * @email 337262603@qq.com
 * @date 2022-03-07 14:56:53
 */
@RestController
@RequestMapping("user/userinfo")
@CrossOrigin
public class UserinfoController {
    @Autowired
    private UserinfoService userinfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //RequiresPermissions("user:userinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userinfoService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping("/Search")
    //RequiresPermissions("user:userinfo:list")
    public R Search(@RequestParam Map<String, Object> params){
        List page = userinfoService.search(params);
        return R.ok().put("page", page);
    }

    @RequestMapping("/login")
    //@RequiresPermissions("user:staffinfo:list")
    public R login(@RequestParam Map<String, Object> params){
        String[] openid = userinfoService.login(params);
        return R.ok().put("openid",openid);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{uid}")
    //@RequiresPermissions("user:userinfo:info")
    public R info(@PathVariable("uid") Integer uid){
		UserinfoEntity userinfo = userinfoService.getById(uid);

        return R.ok().put("userinfo", userinfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("user:userinfo:save")
    public R save(@RequestBody UserinfoEntity userinfo){
		userinfoService.save(userinfo);

        return R.ok();
    }

    @RequestMapping("/insert")
    //@RequiresPermissions("user:userinfo:save")
    public R insert(@RequestParam Map<String, Object> params){
        int id=userinfoService.insert(params);
        String uid=Integer.toString(id);
        return R.ok().put("uid",uid);
    }




    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("user:userinfo:update")
    public R update(@RequestBody UserinfoEntity userinfo){
		userinfoService.updateById(userinfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("user:userinfo:delete")
    public R delete(@RequestBody Integer[] uids){
		userinfoService.removeByIds(Arrays.asList(uids));

        return R.ok();
    }

}
